home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++,comp.lang.java,comp.object,comp.software-eng
- Path: lego.wes.mot.com!mothost!schbbs!news
- From: shang@corp.mot.com (David L. Shang)
- Subject: Re: Pointers are hacks in c++ (portablity hackers etc)
- Reply-To: shang@corp.mot.com
- Organization: MOTOROLA
- Date: Tue, 26 Mar 1996 14:46:25 GMT
- Message-ID: <1996Mar26.144625.2906@schbbs.mot.com>
- References: <4j76i9$pkt@news.roadnet.ups.com>
- Sender: news@schbbs.mot.com (SCHBBS News Account)
- Nntp-Posting-Host: 129.188.128.126
-
- In article <4j76i9$pkt@news.roadnet.ups.com> mwm@roadnet.ups.com (Marlin Meier)
- writes:
- >
- > I have found a book that deals with c++ pointers and pointer fear
- > exclusivly. 464 pages about pointers and memory management! This is
- > what I have been looking for.
-
- 464 pages just about pointers!
-
- In article <EJH.96Mar19163745@larry.gsfc.nasa.gov> ejh@larry.gsfc.nasa.gov
- (Edward Hartnett) writes:
- > Hmmm. Most of what I would call hacked code is not code that violates
- > the standard by depending on undefined behaviour, but rather code that
- > does weird (but usually standard conforming) things with memory or
- > pointers.
-
- Exactly!
-
- In <vpwa1m6wu.fsf_-_@jlbaker.async.csuohio.edu>,
- jabaker@grail.cba.csuohio.edu (jason) writes:
-
- > What exactly constitutes pointer or memory weirdness? I think that
- > going through a list like:
- > list_cell **cell = &head;
- > while (*cell && (*cell)->member != value) cell = &cell->next;
- > looks sort of weird, but is a well established practice. XtOffset and
- > stl's list cell management both do weird things, but encapsulate the
- > gory details, and presumably work as intended. Are these evil hacks?
-
- Yes, they are.
-
- A good, understandable program should not use things like *, &, ->
- to increase the complexicity of the code. A good programming
- language should not encourage users to abuse these weird operators
- in a way like **x and &x->y.
-
- The member selection operator "." and the assignment ":=" are
- sufficient to handle all the regular things. Operator "*" and "&"
- should only be used for some particular situition in a low-level
- system programming, for example, the absolute address is required
- for some embedded system.
-
- Many OO languages including Eiffel and Java have tried to eliminate
- the pointer arithmetic. Operators "*", "&" and "->" are no longer
- required.
-
- But what happens if more than one new object references are required
- from a function interface? In C++ we can do:
-
- void foo (C**x, D** y) { *x =newC(); *y =newD(); };
- C* x;
- D* y;
- foo(&x,&y);
-
- How can we do in Java? Perhaps we have to construct a new class:
-
- class Output
- {
- C x;
- D y;
- };
- class bar
- {
- void foo (Output out) { out.x =newC(); out.y=new D(); };
- bar()
- {
- Output xy;
- foo (xy);
- }
- };
-
- It seems even more clumsy than C++'s code.
-
- Transframe's interface allows output to be a list in the same way as
- we define an input:
-
- input_list_type: output_list_type
-
- Therefore we can have:
-
- function foo (): (C, D) { return (C(), D()); };
- x: C;
- y: D;
- (x, y) := foo();
-
- or, we can write:
-
- xy: (C, D) = foo();
-
- or, if we need to access member of "xy" via member names:
-
- xy: (x:C, y:D) = foo();
-
-
- Note that the "new" operator is eliminated also.
-
- The concept of "name" covers every thing you can find in Java's
- smart reference, C++'s valued variable, or even the low-level
- pointers (if it is required in systems programming). But the
- concept of "name" goes far beyond the current limitation.
-
- Names are themselves objects. Users can define their own names.
- But all names follow the same usage interface.
-
- Some interesting user-defined names:
-
- * net reference:
-
- x: URL#("http://www.foo.com/hello.tf") of TFApplet;
- if (x) x.run();
-
- object my_World3D is World3D
- {
- x: URL#("http://www.foo.com/3d/global.3d") of Model3D;
- enter()
- { if (!x) return;
- i: float =0;
- for (i=0; i<=1; i+=0.1)
- {
- with (x)
- {
- rotate (0, 0, i*360, LOCAL_COORDINATE);
- scale (i,i,i);
- re_display();
- }
- }
- }
- };
-
- Note that the usage of "with" statement.
-
- * team reference:
-
- dancing_team: TEAM of AnimatingObject;
-
- // a dancing team is created
- dancing_team := ( AnimatingCow("cow"),
- AnimatingDog("dog"),
- AnimatingCat("cat")
- );
-
- // team members are handled individually
- foreach (member in dancing_team) member.move_to(somePosition);
-
- // now team members are called together by the team reference
- // "dance" is a method of the "AnimatingObject" class
- dancing_team.dance (anDancingScript);
-
- // now a particular team member is called
- dancing_team.Member("cat").go_away();
-
- // now the team itself (not a member of the team) is called
- // "WelcomeNewMember" is a method of the "TEAM" class
- dancing_team.WelcomeNewMember(AnimatingSheep("sheep"));
-
- For detail, wait for my column on the May issue of Object Currents
- (http://www.sigs.com/objectcurrents/).
-
- David Shang
-
-